<template>
	<view class="login-content">
		<view class="login">
<!-- 			<p style="text-align: center;">欢迎使用</p> -->
			<view class="hint_text">
				系统检测到你还未进行登录<br/>
				请先点击下方按钮授权登录
			</view>
			<p >
				<image style="border-radius: 50rpx;" class='img' src="../../static/basicprofile.png" />
			</p>
			<p style="padding-left: 40upx;">为您提供优质服务,我们需要获取您的以下信息：</p>
			<p style="padding-left: 40upx;">· 您的公开信息(头像、昵称等)</p>
			<button :disabled="isDisabled" @click="getUserProfile">授权进入</button>
<!-- 			<view class='info'>
				<span>仅供内部教师和家长使用</span>
			</view> -->
		</view>
		<u-toast ref="uToast" />
			<Loading />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				code:''
			}
		},
		onLoad() {
			let that=this
			uni.removeStorageSync('token');
			uni.login({
				provider: 'weixin',
				success: function(loginRes) {
					console.log(loginRes)
					that.code=loginRes.code
				}
			})
		},
		methods: {
			getUserProfile() {
				let that = this
				wx.getUserProfile({
					desc: '用于完善资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: (res) => {
						console.log(res)
								let data = {
									code: that.code,
									encryptedData: res.encryptedData,
									iv: res.iv
								}
								// return console.log(data)
								that.$myRuquest('home/login/user_login', data).then(res => {
									if (res.code == 400) {
										uni.setStorageSync('token', res.data.token);
										that.basic()
										that.$refs.uToast.show({
											title: '登录成功',
											type: 'success',
											url: '/pages/index/index',
											isTab: true
										})
									} else {
										that.$refs.uToast.show({
											title: res.msg,
											type: 'error ',
										})
									}
								})
					
					}
				})
			},
			basic() {
				this.$myRuquest('home/user/user').then(res => {
					if (res.code == 400) {
						this.data = res.data
						uni.setStorageSync('myData', res.data);
					}
				})
				this.$myRuquest('home/index/seo_config').then(res => {
					if (res.code == 400) {
						uni.setStorageSync('basic', res.data);
					}
				})
			}
		}
	}
</script>


<style lang='scss'>
	.hint_text{
		font-size: 30upx;
		text-align: center;
		margin-top: 20upx;
	}
	.login-content {
		width: 100%;
		height: 100vh;
		background-color: #FFFFFF;
		.login {
			box-sizing: border-box;
			padding-top: 160rpx;
			width: 95%;
			margin-left: 2.5%;
			height: 100%;
			p: {
				position: relative;
			}
			p:first-of-type {
				font-size: 50rpx;
			}
			p:nth-of-type(1) {
				margin-top: 20rpx;
				font-size: 33rpx;
				color: #999999
			}
			p:nth-of-type(2) {
				width: 100%;
				margin-top: 40rpx;
				display: flex;
				justify-content: center;

				.img {
					width: 300rpx;
					height: 300rpx;
				}
			}

			p:nth-of-type(3) {
				margin-top: 40rpx;
				font-size: 30rpx;
			}

			p:nth-of-type(4) {
				margin-top: 20rpx;
				font-size: 28rpx;
				color: #999999
			}
			button {
				width: 100%;
				height: 100rpx;
				line-height: 100rpx;
				letter-spacing: 3rpx;
				position: relative;
				top: 100rpx;
				border-radius: 50rpx;
			background: linear-gradient(to right, rgb(254, 189, 140), rgb(254, 28, 77));
				color: white;
				font-size: 35rpx;
				font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
			}
/* 			.info{
				width: 70%;
				margin-left: 15%;
				margin-top: 180rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				span:last-child{
					letter-spacing: 2rpx;
					color: rgb(254, 28, 77);
					font-size: 28rpx;
				}
				.select{
					display: inline-block;
					width: 40rpx;
					height: 40rpx;
					border-radius: 50%;
					margin-right: 10rpx;
					box-sizing: border-box;
				}
			} */
		}
	}
</style>
